<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/head.jsp"%>
<script type="text/javascript" src="asserts/plugins/easyui/plugins/jquery-easyui-datagridview/datagrid-detailview.js"></script>
<body>

<table style="width: 100%; height: 100%">
    <tr>
        <td style="width: 50%; vertical-align: top;">
            <table id="datagrid"></table>
        </td>
        <td style="width: 50%; vertical-align: top;">
            <iframe id="menuAddFrame" frameborder="0"
                    style="width: 100%; height: 100%;" scrolling="yes">
            </iframe>
        </td>
    </tr>
</table>

</body>
<script type="text/javascript" charset="UTF-8">
    var dataGrid =  $('#datagrid').datagrid({
        url:'community/adv/query',
        fit: true, //datagrid自适应宽高,
        toolbar : [
            <%--<%if (SysAuthUtil.ifBtn(request, "roleAdd")) {%>--%>
            {id:'btnadd',text:'增加',iconCls:'icon-add',handler:function(rowData){showAdd();}},
            '-',{id:'btnremove',text:'删除',iconCls:'icon-remove',handler:function(){removeBatch();}}
            <%--  <%}%> --%>
            <%--
              '-',{id:'btnremove',text:'删除',iconCls:'icon-remove',handler:function(){removeBatch();}}
              ,'-',{id:'btndisable',text:'禁用',iconCls:'icon-remove',handler:function(){disableBatch();}	}
            ,'-',{id:'btnenabl',text:'启用',iconCls:'icon-add',handler:function(){enableBatch();}}--%>
           //,'-',{id:'btnrefresh',text:'刷新',iconCls:'icon-reload',handler:function(){$('#roleDataGrid').datagrid('reload');}}
        ],
        idField : 'id',singleSelect:true,
        pageSize:20,
        pageList: [20,50,100],//可以设置每页记录条数的列表
        loadFilter : function(data) {
            if (data.status == 0) {
                var total = 0;
                var rows = "";// 当为[]会出现空的两行
                var push = { "total" : total,"rows" : rows};
                $.messager.alert('提示:', '远程服务调用失败', 'error');
                return push;
            } else {
                return data;
            }
        },
        columns:[[
            {field:'id',hidden:true},
            {field:'picUrl',title:'大图',align:'center',width:300},
            {field:'thumbnailUrl',title:'小图',align:'center',width:300},
            {field:'createDate',title:'创建时间 ',align:'center'},
        ]],
        title:'广告记录',
        pagination:true,
        onDblClickRow: function (rowIndex, rowData) {
        $('#roleDataGrid').datagrid('unselectAll');
        $('#roleDataGrid').datagrid('selectRow', rowIndex);
        showInfo(rowData.id);
    }
    });

    function showAdd(){
        document.getElementById("menuAddFrame").src = "community/adv/goadd";
    }

    function showInfo(id){
        document.getElementById("menuAddFrame").src = "community/adv/goinfo?id="+id;
    }

    //批量删除
    function removeBatch() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert('提示', "请选择待操作的记录", 'info');
        } else {
            $.messager.confirm('提示', "确定要删除选中的记录吗？（此操作无法恢复.）", function(r) {
                if (r) {
                    var param = getSelections(rows);
                    load();
                    postAjax({
                        url: 'community/adv/deladv'+param,
                        data: "",
                        callback: function (result) {
                            disLoad();
                            if (result.status == 1) {
                                $.messager.alert("提示信息",(result && result.msg)?result.msg:'操作成功', 'info', function() {
                                    dataGrid.datagrid('reload');
                                    dataGrid.datagrid('getSelections').length=0;
                                });
                            }else{
                                $.messager.alert('提示信息', (result && result.msg)?result.msg:'操作失败', function(r){
                                });
                            }

                        },
                    });
                }
            });
        }
    }

    function getSelections(rows) {
        var ids = [];
        for ( var i = 0; i < rows.length; i++) {
            ids.push(rows[i].id);
        }
        return "?id=" + ids.join(',');
    }

    function getSelectionIds(rows) {
        var ids = [];
        for ( var i = 0; i < rows.length; i++) {
            ids.push(rows[i].id);
        }
        return ids.join(",");
    }

</script>
</html>